package com.wn.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.http.server.RequestPath;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author yellow Docter
 * @date 2022 -11-09
 * @desc
 * 1、GlobalFilter 网关的全局过滤器
 *         拦截所有的请求 业务代码都这个里面
 *
 */
//@Component
public class HelloFilter implements GlobalFilter {

    // ServerWebExchange 处理请求的对象

    // GatewayFilterChain 执行链 是否放行

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        //拿到所有的请求的url，可以通过业务逻辑进行判断
        String path = exchange.getRequest().getURI().getPath();
        System.out.println("path = " + path);

        //当前的过滤器放行
        return chain.filter(exchange);
    }

}
